#!/env/bin/python
#Author:tanqing
# -*- coding: utf-8 -*-
# @Time        : 2021/1/4 14:36
# 1. 读取给定⽂本⽂件，统计单词，计算TOP10
dict={}
with open('sample.txt','r',encoding='utf-8') as f:
    text=f.read().replace('|',' ').replace(',',' ').replace(r'/',' ').replace('-',' ').replace('\\' ,' ').replace('.',' ').strip().lower().split()
    print(text)
    for i in text:
        if i in dict:
            dict[i]+=1
        else:
            dict[i]=1

top=sorted(dict.items(),key=lambda x:x[1],reverse=True )
for i in range(10):
    print(top[i])

# 这里单词统计, 通过replace方法进行替换, 这样的话, 性能会受到影响